<?php

/**
 * This is the model class for table "pc".
 *
 * The followings are the available columns in table 'pc':
 * @property string $id
 * @property string $hostname
 * @property string $ip
 * @property string $mac
 * @property integer $inventory
 * @property integer $factory
 * @property integer $price
 * @property string $prod_year
 * @property string $prod_data
 * @property string $usage_start
 */
class pc extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return pc the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pc';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('inventory, factory, price', 'numerical', 'integerOnly'=>true),
			array('hostname, ip, mac', 'length', 'max'=>45),
			array('prod_year, prod_data, usage_start', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, hostname, ip, mac, inventory, factory, price, prod_year, prod_data, usage_start', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'machines' => array(self::MANY_MANY, 'Machine', 'machine_has_pc(machine_id, pc_id)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'hostname' => 'Hostname',
			'ip' => 'Ip',
			'mac' => 'Mac',
			'inventory' => 'Inventory',
			'factory' => 'Factory',
			'price' => 'Price',
			'prod_year' => 'Prod Year',
			'prod_data' => 'Prod Data',
			'usage_start' => 'Usage Start',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);

		$criteria->compare('hostname',$this->hostname,true);

		$criteria->compare('ip',$this->ip,true);

		$criteria->compare('mac',$this->mac,true);

		$criteria->compare('inventory',$this->inventory);

		$criteria->compare('factory',$this->factory);

		$criteria->compare('price',$this->price);

		$criteria->compare('prod_year',$this->prod_year,true);

		$criteria->compare('prod_data',$this->prod_data,true);

		$criteria->compare('usage_start',$this->usage_start,true);

		return new CActiveDataProvider('pc', array(
			'criteria'=>$criteria,
		));
	}
}